using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Web;
using FwkLight.Application;
using FwkLight.CodeExtensions;
using FwkLight.Domain.Fetching;

namespace Akcedo.Framework.Infrastructure.ASPNet
{
  public interface IRequestItemDictionary : IItemDictionary
  {
    void Remove<Item> ( IItemKey<Item> key );
  }

  public class RequestItemDictionary : IRequestItemDictionary
  {
    [DebuggerNonUserCode]
    public void Add<ItemToPutInContext> ( IItemKey<ItemToPutInContext> key, ItemToPutInContext item )
    {
      if (HttpContext.Current == null)
        return;

      HttpContext.Current.Items[key.Key] = item;
    }

    [DebuggerNonUserCodeAttribute]
    public Item Get<Item> ( IItemKey<Item> key )
    {
      if (HttpContext.Current == null || !Contains(key))
        return default(Item);

      return (Item)HttpContext.Current.Items[key.Key];
    }

    [DebuggerNonUserCodeAttribute]
    public bool Contains<Item> ( IItemKey<Item> key )
    {
      if (HttpContext.Current == null)
        return false;

      return (HttpContext.Current.Items[key.Key] != null);
    }

    public void Remove<ItemToPutIn> ( ItemKey<ItemToPutIn> key )
    {
      throw new NotImplementedException();
    }

    public void Remove<Item> ( IItemKey<Item> key )
    {
      if (HttpContext.Current == null)
        return;

      HttpContext.Current.Items.Remove(key.Key);
    }
  }
}